<template>
  <basic-container>
    <avue-crud
      ref="crud"
      v-model="form"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
    >
      <template
        slot="menu"
        slot-scope="scope"
      >
        <el-button
          type="text"
          @click="showDialog(scope.row.id)"
        >
          查看详情
        </el-button>
      </template>
    </avue-crud>
    <detail-dialog
      :id="id"
      v-model="detailVisible"
    ></detail-dialog>
  </basic-container>
</template>
<script>
import crudMixins from '@/mixins/crud.js';
import { tableOption } from '@/const/crud/app/feedback';
import { fetchList } from '@/api/app/feedback';
import detailDialog from './components/detail-dialog.vue';
export default {
  components: {
    detailDialog,
  },
  mixins: [crudMixins],
  data() {
    return {
      tableOption: tableOption,
      form: {},
      detailVisible: false,
      id: '',
    };
  },
  methods: {
    getList(page, refresh) {
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
          },
          this.searchForm
        )
      )
        .then((res) => {
          this.tableData = res.data.data.records;
          this.page.total = res.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    showDialog(id) {
      this.detailVisible = true;
      this.id = id;
    },
  },
};
</script>
